/**
 * -----------------------------------
 * Copyright (c) 2021-2023
 * All rights reserved, Designed By www.linfeng.tech
 * 林风社交论坛商业版本请务必保留此注释头信息
 * 商业版授权联系技术客服	 QQ:  3582996245
 * 严禁分享、盗用、转卖源码或非法牟利！
 * 版权所有 ，侵权必究！
 * -----------------------------------
 */
package io.linfeng.modules.app.controller;

import io.linfeng.common.utils.Result;
import io.linfeng.common.vo.AppReportListResponse;
import io.linfeng.common.utils.AppPageUtils;
import io.linfeng.common.validator.ValidatorUtils;
import io.linfeng.modules.admin.entity.AppUserEntity;
import io.linfeng.modules.admin.service.ReportService;
import io.linfeng.modules.app.annotation.Login;
import io.linfeng.modules.app.annotation.LoginUser;
import io.linfeng.modules.app.param.ReportAddForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;


/**
 * 用户举报
 *
 * @author linfeng
 * @email 3582996245@qq.com
 * @date 2022-09-01 12:55:12
 */
@RestController
@RequestMapping("app/report")
@Api(tags = "移动端——用户举报")
public class AppReportController {

    @Autowired
    private ReportService reportService;


    @Login
    @PostMapping("/addReport")
    @ApiOperation("用户提交举报")
    public Result save(@RequestBody ReportAddForm request, @ApiIgnore @LoginUser AppUserEntity user){
        ValidatorUtils.validateEntity(request);
		reportService.addReport(request,user);

        return new Result();
    }

    @Login
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页页码", paramType = "query",dataType = "Integer", required = true),
            @ApiImplicitParam(name = "status", value = "状态0待审核 1已处理 2已驳回",paramType = "query", dataType = "Integer", required = true)
    })
    @ApiOperation("用户举报分页")
    public Result<AppPageUtils> list(@RequestParam("page") Integer page,@RequestParam("status") Integer status,@ApiIgnore @LoginUser AppUserEntity user){

        AppPageUtils pages =reportService.listByUser(page,status,user);
        return new Result<AppPageUtils>().ok(pages);
    }


    @Login
    @GetMapping("/detail")
    @ApiOperation("用户举报详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "举报单号id", paramType = "query",dataType = "Integer", required = true)
    })
    public Result<AppReportListResponse> info(@RequestParam("id") Integer id){

        AppReportListResponse report = reportService.detail(id);
        return new Result<AppReportListResponse>().ok(report);
    }

}
